<head>
	<link rel="stylesheet" type="text/css" href="profile_inner.css" />
	<link rel="stylesheet" type="text/css" href="../common/gallery/gallery_compact.css" />
</head>

<img src="/img/icons/back.gif"><a href="frame.php?page=profile"> Return to profile </a>

<div class="padded_text">

<div class="head">My Tagged Users</div>

<p /><img src="/img/arrow_red.gif" /> <a href="do_action.php?actionname=tagall">Tag all users</a>
<br /><img src="/img/arrow_orange.gif" /> <a href="do_action.php?actionname=untagall">Untag all users</a>
<br /><img src="/img/arrow_pink.gif" /> <a href="frame.php?page=taggedme">View users who have tagged me</a>

<p />Updates of tagged users will be visible in your activity feed.

<?php

	error_reporting(0);
	session_start();
	error_reporting(1);
	
	require_once "../common/PinSQL.obj";
	$pinSQL = new PinSQL();
	$pinSQL2 = new PinSQL();
	
	$username = $_SESSION['username'];
	$id = $_SESSION['id'];
	
	$pinSQL->Query("SELECT * FROM memberdata WHERE id='$id'");
	$row = $pinSQL->FetchNextRow();
	
	if (!$row['tagged_users'])
	{
?>

<div class="redtext">You do not currenly have any users tagged.
<br />Tag a user from their profile or by clicking the corresponding link under "<a href="frame.php?page=viewusers">View Users</a>."</div>
<?php
		exit;
	}
	
	$taggedUsers = explode( ",", $row['tagged_users'] );
	
?>

<div class="redtext">Click a user to untag or retag them.</div>

<img src="/img/arrow_green.gif" /> <a href="javascript:UpdateTaggedUsers();">Save changes</a>
<span id="save_status" style="display: none; font-size: 9pt;">Please wait...<img src="/img/rotating_arrow.gif" style="position: relative; top: 4px;"></span>

<table>
<tr>

<?php
	
	for ($i=0; $i<sizeof($taggedUsers); $i++)
	{
		
		if ($i % 4 == 0)
		{
			echo "</tr><tr>";
		}
		
		$thisUser = $taggedUsers[$i];
		
		$pinSQL2->Query("SELECT * FROM members WHERE username='$thisUser'");
		$row2 = $pinSQL2->FetchNextRow();
		$thisID = $row2['id'];
		$thisFirstname = $row2['firstname'];
		$thisLastname = $row2['lastname'];
		$pinSQL2->Query("SELECT * FROM memberdata WHERE id='$thisID'");
		$row2 = $pinSQL2->FetchNextRow();
		
		$picurl = $row2['picurl'];
		if ($picurl)
		{
			$imageSize = getimagesize("userData/" . $thisUser . "/$picurl");
			
			if ($imageSize[0] <= 64)
			{
				$newWidth = $imageSize[0];
				$newHeight = $imageSize[1];
			} else {
				$heightFactor = $imageSize[1] / $imageSize[0];
				$newWidth = 75;
				$newHeight = $newWidth * $heightFactor;
			}
		}
		
?>

<td>
	<div class="medialist_rectangle_active" style="width: 125px;" id="item_<?php echo $i; ?>" onmouseover="HoverOn('<?php echo $i; ?>');" onmouseout="HoverOff('<?php echo $i; ?>');" onclick="SetActive('<?php echo $i; ?>');">
	<span class="smallwht">
		<a href="frame.php?page=profile&user=<?php echo $thisUser; ?>"><?php echo $thisUser; ?></a>
		<div class="horizontal_separation"></div>
		<?php if ($picurl){ ?><center><img src="/members/userData/<?php echo $thisUser; ?>/<?php echo $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" style="border: 2px solid black;"></center><?php } ?>
		<div class="horizontal_separation"></div>
	</span>
	</div>
</td>

<?php

	}
	
?>

</tr>
</table>
	
</div>

<script type="text/javascript">

	var isTagged = [1];
	for (var i=0; i<<?php echo sizeof($taggedUsers); ?>; i++)
	{
		isTagged[i] = 1;
	}

	
	function HoverOn(destID) {}
	function HoverOff(destID) {}
	
	function SetActive(destID)
	{
		destObj = document.getElementById('item_' + destID);
		
		isTagged[destID] = 1 - isTagged[destID];
		
		if (isTagged[destID])
		{
			destObj.className = "medialist_rectangle_active";
		} else {
			destObj.className = "medialist_rectangle";
		}
	}
	
	function UpdateTaggedUsers()
	{
		var outputArray = "";
		for (i=0; i<<?php echo sizeof($taggedUsers); ?>; i++)
		{
			outputArray += isTagged[i];
			if (i != <?php echo (sizeof($taggedUsers) - 1); ?>)
			{
				outputArray += ",";
			}
		}
		
		statusBlock = document.getElementById('save_status');
		statusBlock.style.display = 'block';
		
		// create the XMLHttpRequest object
		var request;
		try { request = new XMLHttpRequest(); }
		catch(e)
		{
		   try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
		   catch(e)
		   {
		        try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
		        catch(e)
		        {
		             alert("Your browser will not support this webpage.");
		             return false;
		        }
		   }
		}
		
		
		request.open("POST", 'do_action.php?actionname=taggedusers', true);
		
		request.onreadystatechange = function()
		{
		   if(request.readyState == 4)
		   {
		        var responseText = request.responseText;
		        statusBlock.style.display = 'none';
		        if (responseText == 1)
		        {
		        	window.location = "/members/frame.php?page=taggedusers";
	        	}
		   }
		}
		
		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send('tagarray=' + outputArray); 
		
     }


	
</script>